﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace SHack.Helper
{
    class DataToFileHelper
    {
        public static void Save(string file, object obj)
        {
            try
            {
                FileStream fs = new FileStream(file, FileMode.Create);
                BinaryFormatter bf = new BinaryFormatter();
                bf.Serialize(fs, obj);
                fs.Close();
            }
            catch (Exception)
            {

            }
        }

        public static object Load(string file)
        {
            object tmp=null;
            if (!File.Exists(file))
                return null;

            try
            {
                FileStream fs = new FileStream(file, FileMode.Open);
                BinaryFormatter bf = new BinaryFormatter();
                tmp = bf.Deserialize(fs);
                fs.Close();
            }
            catch (Exception)
            {

            }

            return tmp;
        }
    }
}